import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../../core/utils/ati_font.dart';

class SignHotExchangeWidget extends StatefulWidget {
  const SignHotExchangeWidget({super.key});

  @override
  State<SignHotExchangeWidget> createState() => _SignHotExchangeWidgetState();
}

class _SignHotExchangeWidgetState extends State<SignHotExchangeWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 5.r),
      padding: EdgeInsets.symmetric(vertical: 20.r, horizontal: 16.r),
      decoration: BoxDecoration(color: Colors.white),
      child: Column(
        children: [
          Text('— 热门兑换 —', style: TextStyle(fontSize: AtiFont.font20)),
          GridView.builder(
            shrinkWrap: true,
            // physics: NeverScrollableScrollPhysics(),
            itemCount: 6,
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2, // 两列
              crossAxisSpacing: 12, // 横向间距
              mainAxisSpacing: 12, // 纵向间距
              childAspectRatio: 0.75, // 宽高比例（可调）
            ),
            itemBuilder: (context, index) {
              return _buildProductCard();
            },
          ),
        ],
      ),
    );
  }

  Widget _buildProductCard() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 6,
            offset: const Offset(0, 3),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          /// 图片部分
          ClipRRect(
            borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
            child: AspectRatio(
              aspectRatio: 1.0,
              child: Image.asset(
                height: 100.r,
                'assets/images/find/news_list_m.png',
                package: 'ati_package',
              ),
            ),
          ),

          /// 文字部分
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '无纺布外卖餐饮奶茶咖啡',
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                    fontSize: 15.sp,
                    fontWeight: FontWeight.w500,
                  ),
                ),
                const SizedBox(height: 6),
                Text.rich(
                  TextSpan(
                    children: [
                      TextSpan(
                        text: '23480积分',
                        style: const TextStyle(
                          color: Colors.green,
                          fontWeight: FontWeight.bold,
                          fontSize: 15,
                        ),
                      ),
                      const TextSpan(
                        text: " 积分",
                        style: TextStyle(color: Colors.green, fontSize: 13),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
